<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <blockquote class="layui-elem-quote quoteBox">
            <form class="layui-form" lay-filter="queryRobtId">
                <div class="layui-input-inline" style="width: 300px">
                    <select id="queryRobtIdVal" name="queryRobtIdVal" lay-filter="queryRobtIdVal" lay-search>
                        <option value="">选择或输入关键词搜索</option>
                    </select>
                </div>
                <button type="button" class="layui-btn layuiadmin-btn-useradmin" id="queryRobotBtn"><i
                        class="layui-icon">
                    &#xe615;</i>机器人配置
                </button>

                <div class="layui-input-inline" style="margin-left: 20px">
                    <span class="layui-badge layui-bg-black">不想发送的文案改成 ‘不发送’ 3个字即可</span>
                    <span class="layui-badge layui-bg-black">文案修改之后记得推送哦！否则不生效</span>
                </div>
            </form>
        </blockquote>


        <form class="layui-form layui-form-pane" action="" lay-filter="example">


            <div class="layui-collapse" lay-accordion>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">导购前提示</h2>
                    <div class="layui-colla-content layui-show"><textarea class="layui-textarea"
                                                                          name="tb_tips"></textarea></div>
                </div>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">商品无佣金（<span style="color: #1E90FF">可用变量：</span> [名称]
                        [商品标题] [抢购网址]）</h2>
                    <div class="layui-colla-content layui-show"><textarea class="layui-textarea"
                                                                          name="tb_no_commission"></textarea></div>
                </div>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">解析淘口令失败（<span style="color: #1E90FF">可用变量：</span>
                        [名称]）</h2>
                    <div class="layui-colla-content layui-show"><textarea class="layui-textarea"
                                                                          name="tb_tkl_error"></textarea></div>
                </div>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">获取商品信息失败追加文案</h2>
                    <div class="layui-colla-content layui-show"><textarea class="layui-textarea"
                                                                          name="tb_no_goodsinfo"></textarea></div>
                </div>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">文本有券（<span style="color: #1E90FF">可用变量：</span> [名称] [淘口令] [积分名称]
                        [补贴金额] [抢购链接]
                        [券后价格] [商品价格] [商品标题] [优惠券面额] [省钱] [到手价]）</h2>
                    <div class="layui-colla-content layui-show"><textarea class="layui-textarea"
                                                                          name="tb_text_yes_coupon"></textarea></div>
                </div>


                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">文本无券（<span style="color: #1E90FF">可用变量：</span> [名称] [淘口令] [积分名称]
                        [补贴金额] [抢购链接]
                        [商品价格] [商品标题] [省钱] [到手价]）</h2>
                    <div class="layui-colla-content layui-show"><textarea class="layui-textarea"
                                                                          name="tb_text_no_coupon"></textarea></div>
                </div>


                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">卡片有券</h2>
                    <div class="layui-colla-content layui-show">
                        （<span style="color: #1E90FF">可用变量：</span> [名称]
                        [积分名称] [补贴金额] [券后价格] [商品价格] [商品标题] [优惠券面额] [淘礼金] [省钱] [到手价]）
                        <input type="text" class="layui-input" name="tb_card_yes_title"></input>
                        卡片内容有券（<span style="color: #1E90FF">可用变量：</span> [名称]
                        [淘口令] [积分名称] [补贴金额] [商品文案] [券后价格] [商品价格] [商品标题] [优惠券面额] [淘礼金] [省钱] [到手价]）
                        <textarea class="layui-textarea" name="tb_card_yes_content"></textarea>
                    </div>
                </div>

                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">卡片无券</h2>
                    <div class="layui-colla-content layui-show">
                        （<span style="color: #1E90FF">可用变量：</span> [名称]
                        [积分名称] [补贴金额] [券后价格] [商品价格] [商品标题] [优惠券面额] [淘礼金] [省钱] [到手价]）
                        <input type="text" class="layui-input" name="tb_card_no_title"></input>
                        卡片内容有券（<span style="color: #1E90FF">可用变量：</span> [名称]
                        [淘口令] [积分名称] [补贴金额] [商品文案] [券后价格] [商品价格] [商品标题] [优惠券面额] [淘礼金] [省钱] [到手价]）
                        <textarea class="layui-textarea" name="tb_card_no_content"></textarea>
                    </div>
                </div>
            </div>

        </form>


        <blockquote class="layui-elem-quote " style="margin-top: 10px">
            <form class="layui-form" lay-filter="updateRobtId">
                <div class="layui-input-inline" style="width: 300px">
                    <select id="updateRobtIdVal" name="updateRobtIdVal" lay-search>
                        <option value="">选择或输入关键词搜索</option>
                    </select>
                </div>
                <button type="button" class="layui-btn layuiadmin-btn-useradmin" id="pushRobotBtn"><i
                        class="layui-icon">
                    &#xe609;</i>单个推送
                </button>
                <div class="layui-input-inline" style="width: 300px">
                    <select id="updateGroupVal" name="updateGroupVal">

                    </select>
                </div>
                <button type="button" class="layui-btn layuiadmin-btn-useradmin" id="pushRobotGroupBtn"><i
                        class="layui-icon">
                    &#xe609;</i>分组推送
                </button>
                <button type="button" class="layui-btn layui-btn-danger" id="pushRobotAllBtn"><i class="layui-icon">&#xe609;</i>全部推送
                </button>
            </form>
        </blockquote>


    </div>
</div>


<script src="/static/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'element', 'laydate'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var element = layui.element;
        var $ = layui.jquery;
        var layedit = layui.layedit;
        var laydate = layui.laydate;
        var updateName = 'xiTong';
        //获取机器人列表
        $.ajax({
            url: "{:url('webFunction/robotOption')}",
            type: 'GET',
            dataType: 'json',
            async: false,
            data: {typeName: 'getOption'},
            success: function (d) {
                $('#queryRobtIdVal').append(d.robotOption);
                $('#updateRobtIdVal').append(d.robotOption);
                $('#updateGroupVal').append(d.groupOption);
                form.val('queryRobtId', {
                    queryRobtIdVal: d.robotChecked
                });
                form.val('updateRobtId', {
                    updateRobtIdVal: d.robotChecked,
                    updateGroupVal: d.gruopChecked
                });
                form.render('select');
            },
            error: function (d) {
                console.log('获取机器人列表失败')
            }
        })


        queryConfig();


        //查看指定机器人配置
        $('#queryRobotBtn').click(function (e) {
            queryConfig();
            updRobotOption($('#queryRobtIdVal').val());

        })
        form.on('select(queryRobtIdVal)', function (e) {
            queryConfig();
            //updRobotOption($('#queryRobtIdVal').val());
        })

        //获取配置
        function queryConfig() {
            var robotId = $('#queryRobtIdVal').val();
            if (updateName == 'mianDan') {
                robotId = 'robotAll';
            }
            $.ajax({
                url: "{:url('manage')}",
                type: 'GET',
                dataType: 'json',
                data: {typeName: 'getConfigure', configreName: updateName, robotId: robotId},
                beforeSend: function () {
                    // loadIndex = layer.load(0, {
                    //     shade: [0.1, '#fff']
                    // });
                },
                complete: function () {
                    // layer.close(loadIndex);
                },
                success: function (d) {
                    form.val('example', {
                        tb_tips: d.tb_tips,
                        tb_tkl_error: d.tb_tkl_error,
                        tb_no_goodsinfo: d.tb_no_goodsinfo,
                        tb_no_commission: d.tb_no_commission,
                        tb_text_yes_coupon: d.tb_text_yes_coupon,
                        tb_text_no_coupon: d.tb_text_no_coupon,
                        tb_card_yes_title: d.tb_card_yes_title,
                        tb_card_no_title: d.tb_card_no_title,
                        tb_card_yes_content: d.tb_card_yes_content,
                        tb_card_no_content: d.tb_card_no_content
                    });
                    form.render();
                },
                error: function (d) {
                    console.log('获取配置失败');
                }
            });


        }

        //保存单个机器人配置
        $('#pushRobotBtn').click(function (e) {
            updateConfig();
        })

        //保存分组机器人
        $('#pushRobotGroupBtn').click(function (e) {
            if (updateName == 'mianDan') {
                layer.alert('该类型文案通用,推送单个机器人即可', {icon: 2, title: '温馨提示'});
                return;
            }
            updateGruop = $('#updateGroupVal').val(), updateType = 2, updateName = updateName, updateData = fromData();
            updateConfigAll();
        })
        //保存全部机器人
        $('#pushRobotAllBtn').click(function (e) {
            if (updateName == 'mianDan') {
                layer.alert('该类型文案通用,推送单个机器人即可', {icon: 2, title: '温馨提示'});
                return;
            }
            updateGruop = '', updateType = 1, updateName = updateName, updateData = fromData();
            updateConfigAll();
        })

        //更新全部
        function updateConfigAll() {
            layui.layer.open({
                title: "推送设置",
                type: 2,
                content: 'updateConfigure.php',
                area: ['700px', '800px'],
                offset: 'auto',
                success: function (layero, index) {

                }
            })
        }

        //提交更新数据
        function updateConfig() {
            var robotId = $('#updateRobtIdVal').val(), dataJson = fromData();
            if (updateName == 'mianDan') {
                robotId = 'robotAll';
            }
            console.log(dataJson)
            if (robotId.length < 5) {
                layer.alert('请选中要推送的机器人');
                return;
            }

            $.ajax({
                url: "{:url('manage')}",
                type: 'POST',
                dataType: 'json',
                data: {'typeName': 'updateConfigure', 'configreName': updateName, 'robotId': robotId, data: dataJson},
                beforeSend: function () {
                    loadIndex = layer.load(1, {
                        shade: [0.1, '#fff']
                    });
                },
                complete: function () {
                    layer.close(loadIndex);
                },
                success: function (d) {
                    if (d.code == 1) {
                        layer.msg(d.msg);
                    } else {
                        layer.alert(d.msg);
                    }
                },
                error: function (d) {
                    console.log('获取配置失败')
                }
            })
        }

        //获取机器人列表
        function updRobotOption(robotId) {
            $.ajax({
                url: '/lib/api/webFunction/robotOption.php',
                type: 'GET',
                dataType: 'json',
                data: {typeName: 'updOption', robotId: robotId}
            })
        }


        //获取表单的值
        function fromData() {
            var data = JSON.stringify({reply: form.val('example')})
            return data;
        }


    })
    ;

</script>

</body>
</html>